﻿#region COPYRIGHT© 2009-2012 Phillip Clark. All rights reserved.
// For licensing information see License.txt (MIT style licensing).
#endregion

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FlitBit.Parse.Tests
{
	[TestClass]
	public class ISO_8601_MatchTests
	{
		[TestMethod]
		public void Iso8601Date_YYYY_MM_DD()
		{
			Assert.IsTrue(CharRule.Iso8601Date.At("1967-08-13", (Cursor)0));
		}

		[TestMethod]
		public void Iso8601Date_Month_RangeCheck()
		{
			Assert.IsFalse(CharRule.Iso8601Date.At("1967-00-13", (Cursor)0));
			for (int i = 1; i < 13; i++)
			{
				Assert.IsTrue(CharRule.Iso8601Date.At(String.Concat("1967-", i.ToString("D2"), "-13"), (Cursor)0));
			}
			Assert.IsFalse(CharRule.Iso8601Date.At("1967-13-13", (Cursor)0));
		}

		[TestMethod]
		public void Iso8601Date_Day_RangeCheck()
		{
			Assert.IsFalse(CharRule.Iso8601Date.At("1967-01-00", (Cursor)0));
			for (int i = 1; i < 32; i++)
			{
				Assert.IsTrue(CharRule.Iso8601Date.At(String.Concat("1967-01-", i.ToString("D2")), (Cursor)0));
			}
			Assert.IsFalse(CharRule.Iso8601Date.At("1967-01-32", (Cursor)0));
		}

		[TestMethod]
		public void Iso8601Time_HH_mm_SS()
		{
			for (int h = 0; h < 23; h++)
			{
				for (int m = 0; m < 60; m++)
				{
					for (int s = 0; s < 60; s++)
					{
						Assert.IsTrue(CharRule.Iso8601Time.At(String.Concat(h.ToString("D2"), ':', m.ToString("D2"), ':', s.ToString("D2")), (Cursor)0));
					}
				}
			}
			// Morning Midnight
			Assert.IsTrue(CharRule.Iso8601Time.At("00:00:00", (Cursor)0));

			// Evening Midnight
			Assert.IsTrue(CharRule.Iso8601TimeWithObscureTimes.At("24:00:00", (Cursor)0));

			// Elusive leap second
			Assert.IsTrue(CharRule.Iso8601TimeWithObscureTimes.At("23:59:60", (Cursor)0));
		}

		[TestMethod]
		public void Iso8601Time_HH_mm_SS_sssssss()
		{
			Assert.IsTrue(CharRule.Iso8601TimeWithFractionalSeconds.At("11:59:59.0123456", (Cursor)0));			
		}

		[TestMethod]
		public void Iso8601DateTime()
		{
			Assert.IsTrue(CharRule.Iso8601DateTime.At("1970-01-01T00:00:00Z", (Cursor)0));
		}

	}
}
